package org.ediba.siri.web.rest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ediba.siri.core.action.domain.ActionUsed;
import org.ediba.siri.core.action.service.ActionService;
import org.springframework.web.bind.annotation.ResponseBody;

public class ActionUsedController extends Controller {
	
	private ActionService actionService;
	public void setActionService(ActionService actionService) {this.actionService = actionService;}
	
	@ResponseBody
	public Map<String,Object> getHandler(HttpServletRequest request, HttpServletResponse response, ActionUsedCommand command){
		List<ActionUsed> actionUseds = null;
		
		if (command.getIdImage() != null)
			actionUseds = this.actionService.usedRetrieveByImage(command.getIdImage());
		else 
			actionUseds = this.actionService.usedRetrieve();
				
		Map<String,Object> _result = new HashMap<String,Object>(4);
		_result.put("data", actionUseds);
		_result.put("total", actionUseds.size());
		_result.put("success", true);
		_result.put("message", "OK");
		return _result;
	}
		
}
